import React, { createContext } from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import store from './store';
import { PersistGate } from 'redux-persist/integration/react'
import { persistor } from './store/index'

import reportWebVitals from './reportWebVitals';
//HashRouter 实现 hash 式路由
//BrowserRouter 实现 history 式路由
import { HashRouter, BrowserRouter } from 'react-router-dom'

import { Provider } from 'react-redux'


var context = createContext()

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  // <React.StrictMode>
  <BrowserRouter>
    {/* Provider 负责将store传入到内层所有组件中. */}
    {/* <context.Provider store={store} value=""> */}
    <Provider store={store}>
      {/* PersistGate 在内部每个组件中获取store中数据的时候, 会自动从localStorage中取出来放入到store中, 每当组件内调用dispatch修改store中数据的时候, 会自动更新数据到localStorage */}
      <PersistGate loading={null} persistor={persistor}>
        <App />
      </PersistGate>
    </Provider>
    {/* </context.Provider> */}
  </BrowserRouter>
  // </React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
